﻿using System;
using System.Speech.Synthesis;

namespace VoiceDeom
{
  public static class VoiceHelper
  {
    static SpeechSynthesizer synth;

    public static void SpeakAsync(string content)
    {
      Dispose();
      synth = new SpeechSynthesizer();
      synth.SpeakAsyncCancelAll();
      synth.SpeakAsync(content);


      //Type type = Type.GetTypeFromProgID("SAPI.SpVoice");

      //dynamic spVoice = Activator.CreateInstance(type);

      //spVoice.Speak("你好,欢迎使用 CSharp 4.0！");
    }

    static void Dispose()
    {
      if (synth != null)
      {
        synth.Dispose();
      }

    }
  }
}
